package com.woniuxy.empserver.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.empserver.entity.TDept;
import com.woniuxy.empserver.servcie.EmpService;
import com.woniuxy.empserver.vo.EmpVo;
import com.woniuxy.empserver.vo.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("emp")
public class EmpController {

    @Autowired
    EmpService empService ;

    @GetMapping("/list")
    public ResponseResult<PageInfo<EmpVo>> list(
            @RequestParam(value = "now",defaultValue = "1") Integer now,
            @RequestParam(value = "size",defaultValue = "2") Integer size,
            @RequestParam(value = "deptId",defaultValue = "0") Integer deptId,
            String ename
    ){
        ResponseResult<PageInfo<EmpVo>> result = new ResponseResult<>();
        try {
            PageInfo<EmpVo>  pageInfo = empService.findByPage(now,size,deptId,ename);
            result.setCode(200);
            result.setMsg("查询成功!");
            result.setData(pageInfo);
        }catch (Exception e) {
            e.printStackTrace();
            result.setMsg("系统错误，请联系管理员!");
            result.setCode(203);
        }
        return result ;
    }


}
